TARGET  := adts
SRCS    := $(wildcard *.c)
OBJS    := ${SRCS:.c=.o}
DEPS    := ${SRCS:.c=.dep}

#Existing dep files
XDEPS   := $(wildcard ${DEPS})

#Target file system
INSTALLDIR := .

CCFLAGS = -std=gnu99 -O2 -Wall -Werror
LDFLAGS =

TOOLCHAIN_ROOT = /home/acra/CodeSourcery/Sourcery_G++_Lite/bin
SYSROOT = /home/acra/ti-dvsdk_dm368-evm_4_02_00_06/br_sysroot
CC = $(TOOLCHAIN_ROOT)/arm-none-linux-gnueabi-gcc
LD = $(TOOLCHAIN_ROOT)/arm-none-linux-gnueabi-ld
LDFLAGS += --sysroot $(SYSROOT)
CCFLAGS += -I$(SYSROOT)/usr/include

.PHONY: all clean distclean test

all: ${TARGET}

ifneq (${XDEPS},)
include ${XDEPS}
endif

$(TARGET): $(OBJS)
	@echo Generating binary [$@]...
	@${CC} ${LDFLAGS} ${LIBS} $^ -o $@

$(OBJS): %.o: %.c %.dep
	@echo Generating objs [$@]...
	@${CC} ${CCFLAGS} -o $@ -c $<

$(DEPS): %.dep: %.c Makefile
	@echo Generating Deps [$@] ...
	@${CC} ${CCFLAGS} -MM $< > $@

install: $(TARGET)
	@echo Installing [$@]....
	@sudo cp ${TARGET} ${INSTALLDIR}

clean:
	@-rm -f *~ *.o *.dep ${TARGET}

test:
	@echo Environment ----------------
	@echo CFLAGS: ${CCFLAGS}
	@echo LIBS: ${LIBS}
	@echo DEPS: ${DEPS}
	@echo XDEPS: ${XDEPS}
